package bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class selectPrice {
	public static double select(int id) {
		PreparedStatement st=null;
		ResultSet rs = null;
		Connection con=ConnectMySql.getConnection();
		double total=0;
		try {
		      st=con.prepareStatement("select * from dish,cart where dish.dishId=cart.dishId and cart.userId=?");
	     	    st.setInt(1,id);
	       		rs=st.executeQuery();
	         	while(rs.next()){
	         		double t=rs.getDouble(3)*rs.getInt(10);
	                total=total+t;
	         	}
			}catch(SQLException e) {
				e.printStackTrace();
		}
		ConnectMySql.closeResultSet(rs);
		ConnectMySql.closeStatement(st);
		ConnectMySql.closeConnection(con);
		return total;
	}
	public static int num(int id) {
		PreparedStatement st=null;
		ResultSet rs = null;
		Connection con=ConnectMySql.getConnection();
		int total=0;
		try {
		      st=con.prepareStatement("select * from dish,cart where dish.dishId=cart.dishId and cart.userId=?");
	     	    st.setInt(1,id);
	       		rs=st.executeQuery();
	         	while(rs.next()){
	         		total++;
	         	}
			}catch(SQLException e) {
				e.printStackTrace();
		}
		ConnectMySql.closeResultSet(rs);
		ConnectMySql.closeStatement(st);
		ConnectMySql.closeConnection(con);
		return total;
	}
}
